package leetcode_贪心;

import java.util.List;

/**
 * 数组列表中的最大距离
 * 算法: 贪心
 *
 * @author yezh
 * @date 2025/2/19 13:40
 */
public class _624 {

    public int maxDistance(List<List<Integer>> arrays) {
        int ans = 0;
        int min = Integer.MAX_VALUE / 2, max = Integer.MIN_VALUE / 2;
        for (List<Integer> array : arrays) {
            int x = array.get(0), y = array.get(array.size() - 1);
            ans = Math.max(ans, Math.max(y - min, max - x));
            min = Math.min(min, x);
            max = Math.max(max, y);
        }
        return ans;
    }

}
